package com.xdwanj.service.impl;

import com.xdwanj.dao.BannerDao;
import com.xdwanj.dao.CommodityDao;
import com.xdwanj.dao.impl.BannerDaoImpl;
import com.xdwanj.dao.impl.CommodityDaoImpl;
import com.xdwanj.pojo.Banner;
import com.xdwanj.pojo.Commodity;
import com.xdwanj.service.CommodityService;
import com.xdwanj.util.PageBean;

public class CommodityServiceImpl implements CommodityService {

    private CommodityDao commodityDao = new CommodityDaoImpl();
    private BannerDao bannerDao = new BannerDaoImpl();

    @Override
    public PageBean<Commodity> findCommodityList(String queryName, int categoryId, int currentPageNo, int pageSize) {
        PageBean customerPageDto = null;
        try {
            customerPageDto = commodityDao.findAllByCommodityAndCategory(queryName, pageSize, currentPageNo, categoryId);

        } catch (Exception e) {
            return null;
        }
        return customerPageDto;
    }

    @Override
    public Commodity findCommodityById(int id) {
        Commodity commodity = null;
        try {
            commodity = commodityDao.findAllById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return commodity;
    }


    @Override
    public PageBean<Banner> findBannerList(int pageSize) {
        PageBean customerPageDto = null;
        try {
            customerPageDto = bannerDao.findBannerList(pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return customerPageDto;
    }

    @Override
    public boolean updateCommodity(Commodity commodity, int catId) {
        try {
            commodityDao.updateById(commodity, catId);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean addCommodity(Commodity commodity, int catId) {
        try {
            commodityDao.add(commodity, catId);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean deleteCommodity(int id) {
        try {
            commodityDao.delete(id);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
